package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.CallbackBo;
import com.java2207.group1.pojo.Callback;
import com.java2207.group1.service.CallbackService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")     // 注意 这里要设置成多例模式
public class WebCallbackListener extends AnalysisEventListener<CallbackBo> {

    @Autowired
    private CallbackService callbackService;


    @Override
    public void invoke(CallbackBo data, AnalysisContext analysisContext) {
        System.out.println(data);
        Callback callback = new Callback();

        // 属性拷贝
        BeanUtils.copyProperties(data, callback);
        callbackService.addCallback(callback);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
